package com.qlogic.commons.utils;

import java.util.Properties;

/**
 * Subclass of java.util.Properties that rejects duplicate definitions of a
 * given property.
 * 
 * @author Mohammed LOUKILI
 */
public class NonOverrideableProperties extends Properties {
	/**
	 * 
	 */
	private static final long serialVersionUID = 87449510153347866L;

	/**
	 * Empty constructor.
	 */
	public NonOverrideableProperties() {
		super();
	}

	/**
	 * Constructor with defaults.
	 * 
	 * @param p
	 *            default properties
	 */
	public NonOverrideableProperties(Properties p) {
		super(p);
	}

	/**
	 * Override put, but do not allow existing values to be changed.
	 * 
	 * @see java.util.Properties#put
	 */
	public Object put(Object key, Object value) {
		Object old = get(key);
		if ((old != null) && (!old.equals(value))) {
			throw new IllegalArgumentException(
					"Cannot override non-overrideable property " + key + " = "
							+ old + " with new value " + value);
		}
		return super.put(key, value);
	}
}
